package networkinstance;

public class Client {
    public static void main(String[] args) {
        try {
            java.net.Socket s = new java.net.Socket("127.0.0.1", 8888);
            java.io.OutputStream os = s.getOutputStream();
            java.io.BufferedWriter bw = new java.io.BufferedWriter(new java.io.OutputStreamWriter(os));
            //向服务器端发送一条消息
            bw.write("测试客户端和服务器通信，服务器接收到消息返回到客户端\n");
            bw.flush();
            //构建IO
            java.io.InputStream is = s.getInputStream();
            //读取服务器返回的消息
            java.io.BufferedReader br = new java.io.BufferedReader(new java.io.InputStreamReader(is));
            String mess = br.readLine();
            System.out.println("服务器：" + mess);
        } catch (java.net.UnknownHostException e) {
            e.printStackTrace();
        } catch (java.io.IOException e) {
            e.printStackTrace();
        }
    }
}
